import { defineStore } from 'pinia'
import { ref } from 'vue'

function initState(){
    return {
        isCollapse:false,
        tags:[
            {
                path: '/home',
                name: 'home',
                label: '首页',
                icon: 'house'
            },
        ],
        currentMenu:null
    };
}
export const useAllDataStore = defineStore('allData', (a) => {

    const state=ref(initState())

    function selectTag(val){
        if (val.name === 'home') {
            state.value.currentMenu = null;
        } else {
            state.value.currentMenu = val;
            let index = state.value.tags.findIndex((item)=>item.name === val.name);
            index === -1 ? state.value.tags.push(val) : '';
        }
    }
    function upDateTags(tag){
        let index = state.value.tags.findIndex((item)=>item.name === tag.name);
        state.value.tags.splice(index,1);
    }

    return {
        state,selectTag,upDateTags
    };
})